package cn.zy.shardbatisdemo.service;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.zy.shardbatisdemo.entity.Tables;
import cn.zy.shardbatisdemo.mapper.TablesMapper;
import cn.zy.shardbatisdemo.service.TablesService;
import org.springframework.util.StringUtils;

@Service(value = "tablesService")
public class TablesServiceImpl implements TablesService{

    @Resource
    private TablesMapper tablesMapper;

    @Override
    public int deleteByPrimaryKey(String id) {
        return tablesMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Tables record) {
        return tablesMapper.insert(record);
    }

    @Override
    public int insertSelective(Tables record) {
        return tablesMapper.insertSelective(record);
    }

    @Override
    public Tables selectByPrimaryKey(String id) {
        return tablesMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Tables record) {
        return tablesMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Tables record) {
        return tablesMapper.updateByPrimaryKey(record);
    }

    /**
     * 因为分表的表名对应的信息存放在tables表中，所以通过这个方法访问，通过对饮的id获取对饮的表名
     * @param id
     * @return
     */
    @Override
    public String getTableName(String id) {
        Tables tables = tablesMapper.getTables(id);
        return StringUtils.isEmpty(tables.getTableName())?null:tables.getTableName();
    }
}
